%% timeWeightedObjective_v1_0
%  Version 1.0
%  Author: Adeyinka Lesi
%  Date: 12/10/19
%  Project: Tumor Growth, Logarithmic Continuum Form
%  Optimization

function [obj] = timeWeightedObjective_v1_0(fit0,fit_weights)

% fit_weights(1) = 0; % ignore fit of first time point
fit = fit0(fit_weights>0).*fit_weights(fit_weights>0); % ignore fit of first time point

% fitting factor (the lower the number, the less leeway for the fits at 
% different times to be different
q = 0.1; %changed 3/15/22: q = 0.01;
exp_max = 300; % avoids returning inf
expfit = exp(min(fit/q,exp_max));
obj = sum(fit.*expfit)/sum(expfit);